package com.shtel.paas.monitorcenter.config.management.alarm.config.web;


import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmConfigDto;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmConfigParam;
import com.shtel.paas.monitorcenter.config.management.alarm.config.entity.AlarmRulesDto;
import com.shtel.paas.monitorcenter.config.management.alarm.config.service.IWarningConfigService;
import com.shtel.paas.sdk.core.RefreshableRestController;
import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

@EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.config.management.alarm.config.mapper")
// mybatis存储库类的包路径
@RefreshableRestController
public class warningConfigController  {

	@Autowired
	IWarningConfigService service;

	
	@GetMapping("/getWarningConfig")
	public PageInfo<AlarmConfigDto> getWarningConfig(@RequestParam("monitoringIndex") String monitoringIndex,
			@RequestParam("page") Integer page,
			@RequestParam("pageSize") Integer pageSize){
		if(monitoringIndex.equals("")) monitoringIndex = null;
		return service.selectAll(monitoringIndex,page,pageSize);
		
	}
	
	@GetMapping("/getWarningMonitoringKpi")
	public List<String> getWarningMonitoringKpi(){
		return service.selectMonitorIndex();
	}
	
	@GetMapping("/updateWarningConfig")
	public int updateWarningConfig(@RequestParam("desc") String desc,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh
			){
		AlarmConfigParam param = new AlarmConfigParam();
		param.setDesc(desc);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		
				return service.updateConfig(param);
		
	}
	
	@GetMapping("/insertWarningConfig")
	public int insertWarningConfig(@RequestParam("desc") String desc,
			@RequestParam("kpi") String kpi,
			@RequestParam("warningLv1ValueLow") String warningLv1ValueLow,
			@RequestParam("warningLv1ValueHigh") String warningLv1ValueHigh,
			@RequestParam("warningLv2ValueLow") String warningLv2ValueLow,
			@RequestParam("warningLv2ValueHigh") String warningLv2ValueHigh,
			@RequestParam("warningLv3ValueLow") String warningLv3ValueLow,
			@RequestParam("warningLv3ValueHigh") String warningLv3ValueHigh
			){
		AlarmRulesDto param = new AlarmRulesDto();
		param.setDesc(desc);
		param.setWarningLv1ValueHigh(warningLv1ValueHigh);
		param.setWarningLv1ValueLow(warningLv1ValueLow);
		param.setWarningLv2ValueHigh(warningLv2ValueHigh);
		param.setWarningLv2ValueLow(warningLv2ValueLow);
		param.setWarningLv3ValueHigh(warningLv3ValueHigh);
		param.setWarningLv3ValueLow(warningLv3ValueLow);
		param.setKpi(kpi);
				return service.insertConfig(param);
		
	}
	
	@GetMapping("/deleteWarningConfig")
	public int deleteWarningConfig(@RequestParam("desc") String desc){
		return service.deleteConfig(desc);
		
	}
}

